<div class="theaters view">
    <h2><?php __('Obra de Teatro'); ?></h2>
    <dl><?php
$i = 0;
$class = ' class="altrow"';
?>
        <dt<?php
if ($i % 2 == 0)
    echo $class;
?>><?php __('Nombre'); ?></dt>
        <dd<?php
        if ($i++ % 2 == 0)
            echo $class;
?>>
        <?php echo $theater['Theater']['name']; ?>
            &nbsp;
        </dd>
        <dt<?php
        if ($i % 2 == 0)
            echo $class;
        ?>><?php __('Nombre de Contacto'); ?></dt>
        <dd<?php
                if ($i++ % 2 == 0)
                    echo $class;
        ?>>
            <?php echo $theater['Theater']['contact_name']; ?>
            &nbsp;
        </dd>
        <dt<?php
            if ($i % 2 == 0)
                echo $class;
            ?>><?php __('Dirección'); ?></dt>
        <dd<?php
            if ($i++ % 2 == 0)
                echo $class;
            ?>>
        <?php echo $theater['Theater']['address']; ?>
            &nbsp;
        </dd>
        <dt<?php
        if ($i % 2 == 0)
            echo $class;
        ?>><?php __('Teléfono Fijo'); ?></dt>
        <dd<?php
        if ($i++ % 2 == 0)
            echo $class;
        ?>>
                <?php echo $theater['Theater']['phone_number']; ?>
            &nbsp;
        </dd>
        <dt<?php
                if ($i % 2 == 0)
                    echo $class;
                ?>><?php __('Teléfono Celular'); ?></dt>
        <dd<?php
                if ($i++ % 2 == 0)
                    echo $class;
                ?>>
<?php echo $theater['Theater']['movil_number']; ?>
            &nbsp;
        </dd>
        <dt<?php
if ($i % 2 == 0)
    echo $class;
?>><?php __('Email'); ?></dt>
        <dd<?php
            if ($i++ % 2 == 0)
                echo $class;
?>>
        <?php echo $theater['Theater']['email']; ?>
            &nbsp;
        </dd>
        <dt<?php
        if ($i % 2 == 0)
            echo $class;
        ?>><?php __('Fecha de Inicio'); ?></dt>
        <dd<?php
                if ($i++ % 2 == 0)
                    echo $class;
        ?>>
            <?php echo date('d/m/Y', strtotime($theater['Theater']['start_date'])); ?>&nbsp;&nbsp;&nbsp;&nbsp;
        <?php echo date('H:i', strtotime($theater['Theater']['start_date'])) . ' - ' . date('H:i', strtotime($theater['Theater']['finish_date'])); ?>
            &nbsp;
        </dd>
        <dt<?php
        if ($i % 2 == 0)
            echo $class;
        ?>><?php __('Descripción'); ?></dt>
        <dd<?php
        if ($i++ % 2 == 0)
            echo $class;
        ?>>
            <?php echo $theater['Theater']['description']; ?>
            &nbsp;
        </dd>
        <dt<?php
            if ($i % 2 == 0)
                echo $class;
            ?>><?php __('Precio de Entrada'); ?></dt>
        <dd<?php
            if ($i++ % 2 == 0)
                echo $class;
            ?>>
<?php echo isset($theater['Theater']['ticket_price']) ? $theater['Theater']['ticket_price'] : '0'; ?>
            &nbsp;
        </dd>
        <dt<?php
if ($i % 2 == 0)
    echo $class;
?>><?php __('Cantidad de Entradas Vendidas'); ?></dt>
        <dd<?php
if ($i++ % 2 == 0)
    echo $class;
?>>
<?php echo isset($theater['Theater']['ticket_sales']) ? $theater['Theater']['ticket_sales'] : '0'; ?>
            &nbsp;
        </dd>
        <dt<?php
if ($i % 2 == 0)
    echo $class;
?>><?php __('Fecha de Carga'); ?></dt>
        <dd<?php
if ($i++ % 2 == 0)
    echo $class;
?>>
        <?php echo date('d/m/Y H:i:s', strtotime($theater['Theater']['created'])); ?>
            &nbsp;
        </dd>
    </dl>
</div>
<br/>
<hr/>
<br/>
<div class="related">
    <h3><?php __('Trajes Asociados'); ?></h3>
    <table cellpadding = "0" cellspacing = "0">
        <tr>
            <th><?php __('Nombre'); ?></th>
        </tr>
<?php
if (empty($theater['Costume'])) {
    ?>
            <tr>
                <td><?php __('No se ha asociado ningún Traje'); ?></td>
            </tr>
    <?php
}

$i = 0;
foreach ($theater['Costume'] as $costume):
    $class = null;
    if ($i++ % 2 == 0) {
        $class = ' class="altrow"';
    }
    ?>
            <tr<?php echo $class; ?>>
                <td><?php echo $costume['name']; ?></td>
            </tr>
        <?php endforeach; ?>
    </table>
</div>
<br/>
<hr/>
<br/>
<div class="related">
    <h3><?php __('Empleados Asociados'); ?></h3>
    <table cellpadding = "0" cellspacing = "0">
        <tr>
            <th><?php __('Nombre'); ?></th>
            <th><?php __('Apellido'); ?></th>
            <th><?php __('Costo'); ?></th>
            <th><?php __('Estado'); ?></th>
        </tr>
            <?php
            if (empty($theater['Employee'])) {
                ?>
            <tr>
                <td colspan="3"><?php echo 'No se ha asociado ningún Empleado'; ?></td>
            </tr>
                <?php
            }
            $i = 0;
            foreach ($theater['TheatersEmployee'] as $employee) {
                $class = null;
                if ($i++ % 2 == 0) {
                    $class = ' class="altrow"';
                }
                ?>
            <tr<?php echo $class; ?>>
    <?php
    if (isset($theater['Employee'][$employee['employee_id']])) {
        ?>
                    <td><?php echo $theater['Employee'][$employee['employee_id']]['first_name']; ?></td>
                    <td><?php echo $theater['Employee'][$employee['employee_id']]['last_name']; ?></td>
        <?php
    } else {
        ?> 
                    <td colspan="2">Sin Definir</td>

        <?php
    }
    ?>
                <td>$<?php echo $employee['cost']; ?></td>
    <?php
    if ($employee['paid'] == 0) {
        $estado = 'No Pagado';
        $clase = 'no_paid';
    } else {
        $estado = 'Pagado';
        $clase = 'paid';
    }
    ?>
                <td class="<?php echo $clase ?>"><?php echo $estado; ?></td>
            </tr>
    <?php
};
?>
        <tr class="tr_total">
            <td colspan="2"><b>Total de Empleados</b></td>
            <td>$<?php echo $theater['Theater']['employee_cost']; ?></td>
            <td></td>
        </tr>
    </table>
</div>
<br/>
<hr/>
<br/>
<div class="related">
    <h3><?php __('Gastos Extra'); ?></h3>
    <table cellpadding = "0" cellspacing = "0">
        <tr>
            <th><?php __('Descripción'); ?></th>
            <th><?php __('Costo'); ?></th>
        </tr>
<?php
if (empty($theater['TheatersExpense'])) {
    ?>
            <tr>
                <td colspan="2"><?php echo 'No se ha asociado ningún Gasto Extra'; ?></td>
            </tr>
    <?php
}
$i = 0;
foreach ($theater['TheatersExpense'] as $expense):
    $class = null;
    if ($i++ % 2 == 0) {
        $class = ' class="altrow"';
    }
    ?>
            <tr<?php echo $class; ?>>
                <td><?php echo $expense['description']; ?></td>
                <td>$<?php echo $expense['cost']; ?></td>
            </tr>
<?php endforeach; ?>
        <tr class="tr_total">
            <td><b>Total de Gastos</b></td>
            <td>$<?php echo $theater['Theater']['expense_cost']; ?></td>
        </tr>
    </table>
</div>
<br/>
<hr/>
<br/>
<h3><?php __('Calculo de Ganancias'); ?></h3>
<div class="resume_total">
    <p><b>Ganancia Festilu</b> = (Precio Entradas x Cantidad Entradas) - Costo Empleados - Costo Gastos</p>
    <p><b>Ganancia Festilu</b> = <?php
        echo '($';
        echo isset($theater['Theater']['ticket_price']) ? $theater['Theater']['ticket_price'] : '0';
        echo ' x ';
        echo isset($theater['Theater']['ticket_sales']) ? $theater['Theater']['ticket_sales'] : '0';
        echo ') - $' . $theater['Theater']['employee_cost'] . ' - $' . $theater['Theater']['expense_cost']
?></p>
    <p><b>Ganancia Festilu</b> = $<?php echo ($theater['Theater']['ticket_price'] * $theater['Theater']['ticket_sales']) - $theater['Theater']['employee_cost'] - $theater['Theater']['expense_cost']; ?></p>
</div>
<br/>
<br/>
<div class="related">
    <h2><?php __('Registro'); ?></h2>
    <table cellpadding = "0" cellspacing = "0">
        <tr>
            <th><?php __('Operación'); ?></th>
            <th><?php __('Usuario'); ?></th>
            <th><?php __('Fecha'); ?></th>
        </tr>
                <?php
                if (empty($activities)) {
                    ?> 
            <tr>
                <td colspan="3">No existen registros</td>
            </tr>
            <?php
        }
        $i = 0;
        foreach ($activities as $activity) {
            $class = null;
            if ($i++ % 2 == 0) {
                $class = ' class="altrow"';
            }
            ?>
            <tr<?php echo $class; ?>>
                <td>
    <?php
    if ($activity['Activity']['type'] == 'create') {
        echo 'Creación';
    } elseif ($activity['Activity']['type'] == 'update') {
        echo 'Actualización';
    } else {
        echo 'Eliminación';
    }
    ?>
                </td>
                <td><?php echo $activity['User']['name']; ?></td>
                <td><?php echo $activity['Activity']['created']; ?></td>
            </tr>
    <?php
}
?>
    </table>
</div>
<br/>
<div class="clear"></div>
<div class="actions">
    <h3><?php __('Acciones'); ?></h3>
    <ul>
        <li><?php echo $this->Html->link(__('Editar Obra de Teatro', true), array('action' => 'edit', $theater['Theater']['id'])); ?> </li>
        <li><?php echo $this->Html->link(__('Eliminar Obra de Teatro', true), array('action' => 'delete', $theater['Theater']['id']), null, sprintf(__('Seguro que desea eliminar esta Obra de Teatro?', true), $theater['Theater']['id'])); ?> </li>
    </ul>
</div>